package com.weibo.util;

import com.weibo.pojo.Attention;
import com.weibo.pojo.Microblog;
import com.weibo.pojo.User;

public class FieldUtils {

	public static void generateDefaultField(Object bean) {
		if (bean.getClass() == User.class) {
			long currentTime = System.currentTimeMillis();
			((User) bean).setCreateAt(currentTime);
			((User) bean).setUpdateAt(currentTime);
			((User) bean).setVersion(1L);
		} else if (bean.getClass() == Attention.class) {
			long currentTime = System.currentTimeMillis();
			((Attention) bean).setCreateAt(currentTime);
			((Attention) bean).setUpdateAt(currentTime);
			((Attention) bean).setVersion(1L);
		} else if (bean.getClass() == Microblog.class) {
			long currentTime = System.currentTimeMillis();
			((Microblog) bean).setCreateAt(currentTime);
			((Microblog) bean).setUpdateAt(currentTime);
			((Microblog) bean).setVersion(1L);
		}
	}

	public static void modifyDefaultField(Object bean) {
		if (bean.getClass() == User.class) {
			Long oldVersion = ((User) bean).getVersion();
			((User) bean).setUpdateAt(System.currentTimeMillis());
			((User) bean).setVersion(++oldVersion);
		} else if (bean.getClass() == Attention.class) {
			Long oldVersion = ((Attention) bean).getVersion();
			((Attention) bean).setUpdateAt(System.currentTimeMillis());
			((Attention) bean).setVersion(++oldVersion);
		} else if (bean.getClass() == Microblog.class) {
			Long oldVersion = ((Microblog) bean).getVersion();
			((Microblog) bean).setUpdateAt(System.currentTimeMillis());
			((Microblog) bean).setVersion(++oldVersion);
		}
	}
}
